class SegmentTree:
    def __init__(self, n):
        self.n = n
        self.info_sum = [0] * (n << 2)
        self.lazy_toggle = [False] * (n << 2)

    def _up(self, root):
        self.info_sum[root] = self.info_sum[root << 1] + self.info_sum[root << 1 | 1]

    def _down(self, l, r, root):
        if self.lazy_toggle[root]:
            mid = (r + l) >> 1
            self._lazy(l, mid, root << 1)
            self._lazy(mid + 1, r, root << 1 | 1)
            self.lazy_toggle[root] = False

    def _lazy(self, l, r, root):
        self.info_sum[root] = r - l + 1 - self.info_sum[root]
        self.lazy_toggle[root] = not self.lazy_toggle[root]

    def toggle(self, L, R):
        def f(l, r, root):
            if r < L or R < l: return
            if L <= l and r <= R:
                self._lazy(l, r, root)
                return
            self._down(l, r, root)
            mid = (l + r) >> 1
            f(l, mid, root << 1)
            f(mid + 1, r, root << 1 | 1)
            self._up(root)

        f(1, self.n, 1)

    def query(self, L, R):
        def f(l, r, root):
            if r < L or R < l: return 0
            if L <= l and r <= R:
                return self.info_sum[root]
            self._down(l, r, root)
            mid = (l + r) >> 1
            return f(l, mid, root << 1) + f(mid + 1, r, root << 1 | 1)

        return f(1, self.n, 1)

import sys
n, m = map(int, sys.stdin.readline().split())
tree = SegmentTree(n)
res = []
for line in sys.stdin.readlines():
    ops = list(map(int, line.split()))
    if ops[0] == 0:
        tree.toggle(ops[1], ops[2])
    else:
        res.append(str(tree.query(ops[1], ops[2])))
sys.stdout.write('\n'.join(res))
